<?php
    if(!$this->session->userdata('logged_in')) {
        redirect('logout');
    }
?>
<div class="page_header_groups">
    <?php echo '<p class=p_header>' . $header_title . '</p>';?>
</div>
<div id="bulletin_container">
    <div id="bulletin_sidebar">
        <div id="notification_post">
            <p class="menu_title">Menu</p>
            <?php
                echo '<p class="sub_group_name">'.anchor(site_url().'authenticated/posts','All', array('id' => 'side_menu_posts')).'</p>';
                echo '<p class="sub_group_name">'.anchor(site_url().'authenticated/bulletin/posts', 'Bulletin Posts', array('id' => 'side_menu_bulletin')).'</p>';
                echo '<p class="sub_group_name">'.anchor(site_url().'authenticated/group/posts', 'Group Posts', array('id' => 'side_menu_group')).'</p>';
            ?>
        </div>
        <div id="year_filter">
            <p class="menu_title">Filter by year</p>
            <?php 
                foreach($years as $bulletin_item) {
                    echo '<div class="filter_year"><p class="year" id="filter_year_'.$bulletin_item['years'].'">';
                    if($this->uri->segment(2) === 'posts' || $this->uri->segment(2) === 'index' || $this->uri->segment(4) === 'index') {
                        echo '<a href="'.site_url().
                                'authenticated/filter_by_year/'.$bulletin_item['years'].'/index">'.$bulletin_item['years'].
                                '</a>';
                    } else if($this->uri->segment(2) === 'group' || $this->uri->segment(2) === 'all_group_post' || $this->uri->segment(4) === 'group') {
                        echo '<a href="'.site_url().
                                'authenticated/filter_by_year/'.$bulletin_item['years'].'/group">'.$bulletin_item['years'].
                                '</a>';
                    } else if($this->uri->segment(2) === 'bulletin' || $this->uri->segment(2) === 'all_bulletin_post' || $this->uri->segment(4) === 'bulletin') {
                        echo '<a href="'.site_url().
                                'authenticated/filter_by_year/'.$bulletin_item['years'].'/bulletin">'.$bulletin_item['years'].
                                '</a>';
                    }
                    echo '</p></div>';
                }
            ?>
        </div>
    </div>
    <div id="bulletin_post">
        <p><?php echo $links; ?></p>
        <?php
            foreach($bulletin as $bulletin_item): 

            if($this->uri->segment(2) === 'posts'){
                echo "<a href='".site_url()."authenticated/posts/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'index'){
                echo "<a href='".site_url()."authenticated/posts/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'bulletin'){
                echo "<a href='".site_url()."authenticated/bulletin/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'all_bulletin_post'){
                echo "<a href='".site_url()."authenticated/bulletin/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'group'){
                echo "<a href='".site_url()."authenticated/group_post/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'all_group_post'){
                echo "<a href='".site_url()."authenticated/group_post/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'filter_by_year'){
                echo "<a href='".site_url()."authenticated/posts/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }else if($this->uri->segment(2) === 'filter_bulletin_post_by_year'){
                echo "<a href='".site_url()."authenticated/posts/read_full_story/".$bulletin_item->post_id."' class='post_content_wrapper'>";
            }
        ?>
        <div class="post">
            <div class="date_pub">
                <p class="pub_day"><?php echo $bulletin_item->day; ?></p>
                <p class="pub_month"><?php echo $bulletin_item->month; ?></p>
                <p class="pub_year"><?php echo $bulletin_item->year; ?></p>
            </div>
            <div class="post_content">
                <?php echo '<p class="post_title">'.$bulletin_item->title.'</p>'; ?>
                <div class="post_summary_wrapper" id="post_summary_<?php echo $bulletin_item->post_id; ?>">
                    <?php echo $bulletin_item->summary; ?>
                </div>
                <?php
                    if($this->uri->segment(2) !== 'bulletin'){
                        echo '<p class="location"><span>Location: </span>'.$bulletin_item->lokasyon.'</p>';    
                    }
                ?>
            </div>
            <div class="balancer"></div>
        </div>
        <?php 
            echo '</a>';
            endforeach; 
        ?>
        <p><?php echo $links; ?></p>
    </div>
    <div class="balancer"></div>
</div>
<div class="balancer"></div>


<script>
    var tiles1 = document.getElementsByClassName('date_pub');
  
    for(var i = 0; i < tiles1.length; i++) {
        var tile = tiles1[i];
        var color = get_random_color();
        tile.style.background = get_random_color();
    }

    function get_random_color() {
        var letters = '678abcd'.split('');
        var color = '#';
        for (var i = 0; i < 6; i++ ) {
            color += letters[Math.round(Math.random() * 6)];
        }
        return color;
    }
</script>
